<!doctype html>
<html lang="zh_cn" itemscope itemtype="http://schema.org/Person">
<head>
            <meta charset="utf-8">
        <!-- Site Meta Data -->
        <title>聊聊Cron表达式</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="技术博客,涉及Java/PHP/Python/Javascript等,聊聊程序,聊聊生活,聊聊事实,聊聊育儿">
        <meta name="keywords" content="编码经验,技术分享,生活积累,实事评说">
        <meta name="author" content="布丁缘">

        <link rel="shortcut icon" href="">

        <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700' rel='stylesheet' type='text/css'>
        <!-- Style Meta Data -->
        <link rel="stylesheet" href="https://www.ddkiss.com/theme/css/style.css" type="text/css"/>
        <link rel="stylesheet" href="https://www.ddkiss.com/theme/css/pygments.css" type="text/css"/>

        <!-- Feed Meta Data -->
            <link href="https://www.ddkiss.com/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"
                  title="一个程序员的简单生活 ATOM Feed"/>


    <meta name="keywords" content="">
    <link rel="stylesheet" href="//dn-coding-net-public-file.qbox.me/Coding-Comments/v0.1.0/default.css">
</head>

<body>
<!-- Sidebar -->
<aside>
    <center><h1><a href="/" style="color:#fff"><img id="avatar" src="/images/avatar.jpg"></a></h1></center>
        <p>一个程序员的简单生活</p>
    <br>
    <nav class="nav">
        <ul class="list-bare">
                <li><a class="nav__link" href="https://www.ddkiss.com/category/chang-yong-ji-qiao.html">常用技巧</a></li>
                <li><a class="nav__link" href="https://www.ddkiss.com/category/kai-fa-huan-jing.html">开发环境</a></li>
                <li><a class="nav__link" href="https://www.ddkiss.com/category/sheng-huo-dian-di.html">生活点滴</a></li>

                <li><a class="nav__link" href="/pages/books.html">书单</a></li>
                <li><a class="nav__link" href="/pages/movies.html">影单</a></li>
                <li><a class="nav__link" href="/pages/downloads.html">下载</a></li>
                <li><a class="nav__link" href="/pages/about.html">关于我</a></li>


        </ul>
    </nav>


    <form>
      <input type="text"  id="bdcsMain"/>
    </form>

</aside>

<!-- Content -->
<article>
  <main>
    <nav>
      <a href="/">首页</a>
      <a href="/archives.html">归档</a>
      <a href="/categories.html">分类</a>
      <a href="/tags.html">标签</a>
      <a href="/pages/about.html">关于我</a>
    </nav>
  </main>
    <section id="content">
        <article>
            <h2 class="post_title post_detail"><a href="https://www.ddkiss.com/archives/23.html" rel="bookmark"
                                                  title="Permalink to 聊聊Cron表达式">聊聊Cron表达式</a></h2>

            <div class="post_list">
                <span>作者：</span><a href="https://www.ddkiss.com/author/bu-ding-yuan.html">布丁缘</a>
                <span class="post_category">分类：<a href="https://www.ddkiss.com/category/kai-fa-huan-jing.html" rel="bookmark"
                                               title="Permalink to 开发环境">开发环境</a></span>
                <span class="post_date">  时间：2017-09-25 17:51:00</span>

            </div>
            <div class="entry-content blog-post">
                <h3>前言</h3>
<p>很多地方都曾用到 cron 表达式，但是每次用都是去网上搜一通，看看别人的例子，然后改吧改吧。今天又需要用到这个知识点，就花了点时间把这个整理下。</p>
<h3>主要内容</h3>
<p>关于 cron 表达式的文章非常多，但是总是看得云里雾里，体会不深。下面总结下</p>
<h4>1. 格式</h4>
<p>形象点是<code>秒　分　时　日　月　周　年</code>，比如<code>* * * 1 1 ? *</code>。先对可能用到的符号简单介绍下</p>
<ul>
<li>
<p>常用符号</p>
<ul>
<li>
<p><code>*</code>,通配符，表示任意。</p>
</li>
<li>
<p><code>?</code>,通配符，只能用于"日"和"周"，但是因为“一个月中的第几天(1-31)”和“一个星期的第几天(1-7)”是会冲突的。所以当任一个确定了，另一个只能写<code>?</code>，而不是<code>*</code>。区别<code>*</code>这里是“有限制的任意”。如果两者都是任意，则按如下表示<code>0 0 0 * 1 ?</code>，也就是一个<code>*</code>，一个<code>?</code></p>
</li>
<li>
<p><code>-</code>，区间，比如<code>1-5</code></p>
</li>
<li>
<p><code>/</code>，表示间隔，比如<code>1/5 * * * * ?</code>从第１秒钟开始，每隔５秒运行一次</p>
</li>
</ul>
</li>
<li>
<p>各个字段</p>
<ul>
<li>
<p><code>秒</code>，范围是'0-59'</p>
</li>
<li>
<p><code>分</code>，范围是'0-59'</p>
</li>
<li>
<p><code>时</code>，范围是'0-24'</p>
</li>
<li>
<p><code>日</code>，范围是'1-31'，一个月的第几天</p>
</li>
<li>
<p><code>月</code>，范围是'1-12'</p>
</li>
<li>
<p><code>周</code>，范围是'1-7'，其中<code>1</code>表示星期日</p>
</li>
<li>
<p><code>年</code>，可以省略不写</p>
</li>
</ul>
</li>
</ul>
<h4>2. 例子</h4>
<div class="highlight"><pre><span></span>0 0 10,14,16 * * ?　每天10,14,16点触发
0 0/30 9-17 * * ?    每天9点到17点每隔30分钟触发
0 0 12 ? * WED    每周三12点触发
0 15 10 ? * MON-FRI    每周一到周五10点15分触发
0 10,44 14 ? 3 WED    3月份每周三14点10分，14点44分触发
0 0/5 14 * * ?    每天14点到14点55分之间每隔5分钟触发
</pre></div>


<h4>3. 常用链接</h4>
<p><a href="http://www.cronmaker.com/">在线校验cron表达式</a>
<a href="http://blog.csdn.net/cpf2016/article/details/46625457">Java验证</a>
<a href="http://www.cnblogs.com/linjiqin/archive/2013/07/08/3178452.html">Cron表达式详解</a></p>
            </div>
            <div class="post_list">
              <div><span>Tags : </span>
              </div>
            </div>
        </article>
        <div id="container"></div>
        <script type="text/javascript" src="//dn-coding-net-public-file.qbox.me/Coding-Comments/v0.1.0/gitment.min.js"></script>
        <script>
            var gitment = new Gitment({
              owner: 'whusl',
              repo: 'BlogComments',
              oauth: {
                client_id: '621866266817529fba46681653017809',
                client_secret: '14188411740b12ae52159cee9b586bf85cd54125',
              },
            })
            document.getElementById('container').appendChild(gitment.render())
          </script>
    </section>
</article>

<!-- Footer -->
    <footer>
        <p> &copy;2017-2020&nbsp;<a href="http://www.miitbeian.gov.cn/" target="_blank">鄂ICP备17020200号</a>
          Blog powered by <a href="http://getpelican.com/">Pelican</a>
        </p>
    </footer>

    <!-- Analytics -->
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?88c55edaf311dbacac56a16316b04c8b";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>

<script type="text/javascript">(function(){document.write(unescape('%3Cdiv id="bdcs"%3E%3C/div%3E'));var bdcs = document.createElement('script');bdcs.type = 'text/javascript';bdcs.async = true;bdcs.src = 'http://znsv.baidu.com/customer_search/api/js?sid=14490611060029767912' + '&plate_url=' + encodeURIComponent(window.location.href) + '&t=' + Math.ceil(new Date()/3600000);var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(bdcs, s);})();</script>

</body>
</html>